home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / plotting / imagetoo / imagetl1.lha / Imagetool / src+obj / help.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-03-11  |  13.6 KB  |  485 lines

  1. /* cat > headers/help.h << "EOF" */
  2. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  3. /* help.h: header for help.c file            */
  4. /*        Create help windows. Within the help window, */
  5. /*       user can read help files by selecting    */
  6. /*       through the menu and report bugs using    */
  7. /*       'bug report'.                */
  8. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  9. /* SCCS information: %W%    %G% - NCSA */
  10.  
  11. #define    help_h        1
  12.  
  13. #include "all.h"
  14. #include "newext.h"
  15.  
  16.     static Panel_item patn_item, msg_item, deliver_button;
  17.  
  18.     static Textsw_index first;
  19.  
  20.     static char *bugf;
  21.  
  22.     static void bug_deliver();
  23.     static void help_done();
  24.     static int msgwrite();
  25.     static void pattern_search();
  26.     static void reset_text();
  27.     static Panel_setting search_proc();
  28.  
  29.  
  30. /* EOF */
  31. /* cat > src+obj/help/bug_deliver.c << "EOF" */
  32. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  33. /* bug_deliver: (static) deliver bug            */
  34. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  35. /* SCCS information: %W%    %G% - NCSA */
  36.  
  37. /* #include "help.h" */
  38.  
  39. static void
  40. bug_deliver ()
  41. {
  42.  
  43. /* Implementation note(s):
  44.     1. The mail command is assumed to be executed in the C-Shell.
  45. */
  46.  
  47.     Textsw_index    start, end, newstart, newend, next_pos;
  48.     int             next_newline, msg_length;
  49.     char           *p_defaultstr;
  50.  
  51.     static int      startup = 1;
  52.     static char     bug_email[MAXNAMELEN] = DEFAULT_BUG_EMAIL_ADDRESS;
  53.  
  54.     if (startup)
  55.     {        /* try to get E-mail address from defaults */
  56.         startup = 0;
  57.         if ((p_defaultstr = get_defaults (BUG_EMAIL_ADDRESS)) == NULL)
  58.         {
  59.             sprintf (wkstr, "Warning: No defaults bug E-Mail address - %s used.", bug_email);
  60.             msg_write (wkstr);
  61.         }
  62.         else
  63.             strcpy (bug_email, p_defaultstr);
  64.     }
  65.     sprintf (wkstr, "mail -s 'ImageTool 1.1 Bug Report' %s << EOF\r", bug_email);
  66.     tty_write (wkstr);
  67.  
  68.         /* loop through the lines */
  69.     newstart = start = 0;
  70.     if ((end = (Textsw_index) window_get (textsw, TEXTSW_LENGTH)) == 0)
  71.     {        /* no message */
  72.         tty_write ("EOF\r");
  73.         return;
  74.     }
  75.     end = end - 1;
  76.     while ((next_newline = textsw_find_bytes (textsw, &newstart, &newend, "\n", 0)) != -1)
  77.     {
  78.         msg_length = ((newstart - start) > MAXNAMELEN) ? MAXNAMELEN - 1 : (newstart - start) + 1;
  79.         if ((newstart - start) > MAXNAMELEN)    /* name too long - putout message and line will be truncated */
  80.         {
  81.             sprintf (wkstr, "Warning: Line of bug message truncated to %d characters.", MAXNAMELEN - 1);
  82.             msg_write (wkstr);
  83.         }
  84.         next_pos = (Textsw_index) window_get (textsw, TEXTSW_CONTENTS, start, msgstr, msg_length);
  85.         if (next_pos != start + msg_length)
  86.         {
  87.             msg_write ("Internal error: Could not copy line from textsubwindow to buffer. Skipped.");
  88.         }
  89.         else
  90.         {
  91.             tty_write (" ");    /* push over the line by a space to be sure that it doesn't start with an EOF */
  92.             msgstr[msg_length + 1] = '\0';
  93.             tty_write (msgstr);
  94.         }
  95.         if (newstart == end)    /* done */
  96.             break;
  97.         else
  98.             start = newstart += 1;
  99.     }
  100.     if (newstart != end)    /* last line does not end in a newline */
  101.     {
  102.         msg_length = ((end - start) > MAXNAMELEN) ? MAXNAMELEN - 1 : (end - start) + 1;
  103.         if ((end - start) > MAXNAMELEN)    /* name too long - putout message and line will be truncated */
  104.         {
  105.             sprintf (wkstr, "Warning: Line of bug message truncated to %d characters.", MAXNAMELEN - 1);
  106.             msg_write (wkstr);
  107.         }
  108.         next_pos = (Textsw_index) window_get (textsw, TEXTSW_CONTENTS, start, msgstr, msg_length);
  109.         if (next_pos != start + msg_length)
  110.         {
  111.             msg_write ("Internal error: Could not copy line from textsubwindow to buffer. Skipped.");
  112.         }
  113.         else
  114.         {
  115.             tty_write (" ");    /* push over the line by a space to be sure that it doesn't start with an EOF */
  116.             msgstr[msg_length + 1] = '\0';
  117.             tty_write (msgstr);
  118.             tty_write ("\n");
  119.         }
  120.     }
  121.     tty_write ("EOF\r");
  122.     return;
  123. }
  124. /* EOF */
  125. /* cat > src+obj/help/bug_report.c << "EOF" */
  126. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  127. /* bug_report: bug_report let user write         */
  128. /*           comments/questions/problems in text    */
  129. /*           window and press on 'deliver' button to    */
  130. /*           send                    */
  131. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  132. /* SCCS information: %W%    %G% - NCSA */
  133.  
  134. /* #include "help.h" */
  135.  
  136. bug_report ()
  137. {
  138.     window_set (textsw,
  139.             TEXTSW_READ_ONLY, FALSE,    /* writeable */
  140.             0);
  141.     window_set (help_window,
  142.             FRAME_LABEL, "Bug report --- Imagetool 1.1",
  143.             WIN_SHOW, TRUE,
  144.             0);
  145.     panel_set (deliver_button, PANEL_SHOW_ITEM, TRUE, 0);
  146.     textsw_reset (textsw, 0, 0);
  147.     msgwrite ("Please compose message in text window below . . .");
  148. }
  149. /* EOF */
  150. /* cat > src+obj/help/create_help_menu.c << "EOF" */
  151. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  152. /* create_help_menu: create menu items under 'HELP'    */
  153. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  154. /* SCCS information: %W%    %G% - NCSA */
  155.  
  156. /* #include "help.h" */
  157.  
  158. create_help_menu ()
  159. {
  160.  
  161.     help_menu = menu_create (MENU_FONT, font_menu,
  162.                  MENU_STRINGS,     "Basics",
  163.                         "Menus",
  164.                         "Button usages",
  165.                          "Examples",
  166.                          /* "Error info", */
  167.                          "Bug report",
  168.                          0,
  169.                  MENU_NOTIFY_PROC, help_proc,
  170.                  0);
  171. }
  172. /* EOF */
  173. /* cat > src+obj/help/create_helpsw.c << "EOF" */
  174. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  175. /* create_helpsw: build help window and buttons        */
  176. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  177. /* SCCS information: %W%    %G% - NCSA */
  178.  
  179. /* #include "help.h" */
  180.  
  181. create_helpsw ()
  182. {
  183.     Panel           panel;
  184.     Rect           *canvas_rect, *panel_rect;
  185.     Pixfont        *pfont, *tfont;
  186.     int             x_offset = 100;
  187.     int             y_offset = 25;
  188.     int             button_offset;
  189.  
  190.          /* location of the help_window: put it in the canvas
  191.             region offset a little so that everything is
  192.             visible. */
  193.  
  194.     canvas_rect = (Rect *) window_get (canvas, WIN_RECT);
  195.  
  196.     help_window = window_create (base, FRAME,
  197.                      FRAME_SHOW_LABEL, TRUE,
  198.                      FRAME_LABEL, "Help_window, ImageTool",
  199.                      WIN_X, (canvas_rect->r_left + x_offset),
  200.                      WIN_Y, (canvas_rect->r_top + y_offset),
  201.                      0);
  202.     panel = window_create (help_window, PANEL,
  203.                    WIN_FONT, font_panel,
  204.                    WIN_HEIGHT, 60,
  205.                    0);
  206.  
  207.     textsw = window_create (help_window, TEXTSW,
  208.                 WIN_BELOW, panel,
  209.                 WIN_X, 0,
  210.                 WIN_HEIGHT, 400,
  211.                 0);
  212.  
  213.     pfont = (Pixfont *) window_get (panel, WIN_FONT);
  214.     tfont = (Pixfont *) window_get (textsw, WIN_FONT);
  215.     if (pfont->pf_defaultsize.x > tfont->pf_defaultsize.x)
  216.             /* panel font larger */
  217.         window_set (panel, WIN_COLUMNS, 80, 0);
  218.     else
  219.         window_set (textsw, WIN_COLUMNS, 80, 0);
  220.  
  221.     patn_item = panel_create_item (panel, PANEL_TEXT,
  222.                        PANEL_ITEM_X, 10,
  223.                        PANEL_ITEM_Y, 10,
  224.                        PANEL_LABEL_STRING, "Search Pattern:",
  225.                        PANEL_VALUE_STORED_LENGTH, MAXNAMELEN - 1,
  226.                        PANEL_VALUE_DISPLAY_LENGTH, 30,
  227.                        PANEL_LABEL_BOLD, TRUE,
  228.                        PANEL_MENU_TITLE_STRING, "Help search",
  229.                        PANEL_MENU_CHOICE_STRINGS, "Return - Search pattern", 0,
  230.                        PANEL_MENU_CHOICE_FONTS, font_menu, 0,
  231.                        PANEL_MENU_CHOICE_VALUES, CR, 0,
  232.                        PANEL_SHOW_MENU, TRUE,
  233.                        PANEL_NOTIFY_LEVEL, PANEL_ALL,
  234.                        PANEL_NOTIFY_PROC, search_proc,
  235.                        0);
  236.     msg_item = panel_create_item (panel, PANEL_MESSAGE,
  237.                       PANEL_ITEM_X, 30,
  238.                       PANEL_ITEM_Y, 30,
  239.                       0);
  240.  
  241.     button_offset = (strlen ("Search Pattern:") + 30 + 4) * font_panel->pf_defaultsize.x;
  242.     deliver_button = panel_create_item (panel, PANEL_BUTTON,
  243.                         PANEL_ITEM_X, button_offset,
  244.                         PANEL_ITEM_Y, 10,
  245.                         PANEL_LABEL_IMAGE, panel_button_image (panel, "Deliver", 7, font_panel_button),
  246.                         PANEL_FEEDBACK, PANEL_INVERTED,
  247.                         PANEL_SHOW_ITEM, FALSE,
  248.                         PANEL_NOTIFY_PROC, bug_deliver,
  249.                         0);
  250.  
  251.     button_offset += (strlen ("Deliver") + 2) * font_panel_button->pf_defaultsize.x;
  252.     panel_create_item (panel, PANEL_BUTTON,
  253.                PANEL_ITEM_X, button_offset,
  254.                PANEL_ITEM_Y, 10,
  255.                PANEL_LABEL_IMAGE, panel_button_image (panel, "Top", 6, font_panel_button),
  256.                PANEL_FEEDBACK, PANEL_INVERTED,
  257.                PANEL_NOTIFY_PROC, reset_text,
  258.                0);
  259.  
  260.     button_offset += (strlen ("Deliver") + 1) * font_panel_button->pf_defaultsize.x;
  261.     panel_create_item (panel, PANEL_BUTTON,
  262.                PANEL_ITEM_X, button_offset,
  263.                PANEL_ITEM_Y, 10,
  264.                PANEL_LABEL_IMAGE, panel_button_image (panel, "Done", 6, font_panel_button),
  265.                PANEL_FEEDBACK, PANEL_INVERTED,
  266.                PANEL_NOTIFY_PROC, help_done,
  267.                0);
  268.     window_fit (help_window);
  269.  
  270.  /* set color map same with imagetool */
  271.     (void) color_help_win ();
  272. }
  273. /* EOF */
  274. /* cat > src+obj/help/help_done.c << "EOF" */
  275. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  276. /* help_done: (static) done with help            */
  277. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  278. /* SCCS information: %W%    %G% - NCSA */
  279.  
  280. /* #include "help.h" */
  281.  
  282. static void
  283. help_done ()
  284. {
  285.     window_set (help_window, WIN_SHOW, FALSE, 0);
  286.     if (panel_get (deliver_button, PANEL_SHOW_ITEM, 0))
  287.         panel_set (deliver_button, PANEL_SHOW_ITEM, FALSE, 0);
  288. }
  289. /* EOF */
  290. /* cat > src+obj/help/help_handler.c << "EOF" */
  291. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  292. /* help_handler: handler to display menu when 'HELP'    */
  293. /*         is selected                 */
  294. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  295. /* SCCS information: %W%    %G% - NCSA */
  296.  
  297. /* #include "help.h" */
  298.  
  299. help_handler (item, event)
  300.     Panel_item      item;
  301.     Event          *event;
  302. {
  303.     if (display_panel_menu (item, event, menu_panel, help_menu))
  304.         help_proc (help_menu, menu_get (help_menu, MENU_NTH_ITEM, 1));
  305. }
  306. /* EOF */
  307. /* cat > src+obj/help/help_proc.c << "EOF" */
  308. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  309. /* help_proc:  handler called when a menu item is    */
  310. /*           selected                    */
  311. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  312. /* SCCS information: %W%    %G% - NCSA */
  313.  
  314. /* #include "help.h" */
  315.  
  316. void
  317. help_proc (m, mi)
  318.     Menu            m;
  319.     Menu_item       mi;
  320. {
  321.     char            str[MAXNAMELEN];
  322.     char            fn[MAXNAMELEN];
  323.  
  324.     fn[0] = '\0';
  325.  
  326.         /* get menu string name */
  327.     strcpy (str, (char *) menu_get (mi, MENU_STRING));
  328.  
  329.         /* initialize the search position for patterns */
  330.     first = 0;
  331.  
  332.         /* for mailing bugs */
  333.     if (!strcmp ("Bug report", str))
  334.     {
  335.         bug_report ();
  336.         return;
  337.     }
  338.  
  339.     if (panel_get (deliver_button, PANEL_SHOW_ITEM, 0))
  340.         panel_set (deliver_button, PANEL_SHOW_ITEM, FALSE, 0);
  341.  
  342.     if (!strcmp ("Menus", str))
  343.         sprintf (fn, "%s/imagetool_menus", help_dir);
  344.     else if (!strcmp ("Basics", str))
  345.         sprintf (fn, "%s/imagetool_basics", help_dir);
  346.     else if (!strcmp ("Button usages", str))
  347.         sprintf (fn, "%s/imagetool_buttons", help_dir);
  348.     else if (!strcmp ("Examples", str))
  349.         sprintf (fn, "%s/imagetool_examples", help_dir);
  350.     /* else if (!strcmp ("Error info", str))
  351.         sprintf (fn, "%s/imagetool_errors", help_dir); */
  352.  
  353.     read_help_file (fn);
  354. }
  355. /* EOF */
  356. /* cat > src+obj/help/msgwrite.c << "EOF" */
  357. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  358. /* msgwrite: (static) write message            */
  359. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  360. /* SCCS information: %W%    %G% - NCSA */
  361.  
  362. /* #include "help.h" */
  363.  
  364. static int
  365. msgwrite (msg)
  366.     char           *msg;
  367. {
  368.     panel_set (msg_item, PANEL_LABEL_STRING, msg, 0);
  369. }
  370. /* EOF */
  371. /* cat > src+obj/help/pattern_search.c << "EOF" */
  372. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  373. /* pattern_search: (static) pattern search        */
  374. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  375. /* SCCS information: %W%    %G% - NCSA */
  376.  
  377. /* #include "help.h" */
  378.  
  379. static void
  380. pattern_search (item)
  381.     Panel_item      item;
  382. {
  383. /* Implementation note(s):
  384.     1. If first is beyond the end of text, textsw_find_bytes, will
  385.        wrap to the beginning in the search. Last is only returned.
  386. */
  387.     char            str[MAXNAMELEN];
  388.     Textsw_index    last;
  389.     int             len;
  390.  
  391.     strcpy (str, (char *) panel_get_value (item));
  392.     len = strlen (str);
  393.     if (len > 0)
  394.     {
  395.         if (textsw_find_bytes (textsw, &first, &last, str, len, 0) > 0)
  396.         {
  397.             msgwrite ("");    /* message cleared */
  398.             textsw_set_selection (textsw, first, last, 1);
  399.             textsw_possibly_normalize (textsw, first);
  400.             first++;
  401.         }
  402.         else
  403.             msgwrite ("Pattern not found");
  404.     }
  405. }
  406. /* EOF */
  407. /* cat > src+obj/help/read_help_file.c << "EOF" */
  408. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  409. /* read_help_file: display a help file in a text window */
  410. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  411. /* SCCS information: %W%    %G% - NCSA */
  412.  
  413. /* #include "help.h" */
  414.  
  415. read_help_file (fn)
  416.     char           *fn;
  417. {
  418.     Textsw_status   status;
  419.     int             len;
  420.  
  421.     len = strlen (fn);
  422.  
  423.     msgwrite ("");
  424.     window_set (textsw,
  425.             TEXTSW_FILE, fn,    /* load file */
  426.             TEXTSW_STATUS, &status,
  427.             0);
  428.     if (status == TEXTSW_STATUS_OKAY)
  429.     {        /* loading succeeded */
  430.         reset_text ();    /* start at top of file */
  431.         window_set (textsw,
  432.                 TEXTSW_READ_ONLY, TRUE,    /* read only */
  433.                 0);
  434.         window_set (help_window,
  435.                 FRAME_LABEL, fn,
  436.                 WIN_SHOW, TRUE,
  437.                 0);
  438.     }
  439.     else
  440.     {
  441.         sprintf (wkstr, "Error: Help file is bad or does not exist.\n       File = %s", fn);
  442.         msg_write (wkstr);
  443.     }
  444.     return;
  445. }
  446. /* EOF */
  447. /* cat > src+obj/help/reset_text.c << "EOF" */
  448. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  449. /* reset_text: (static) reset text            */
  450. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  451. /* SCCS information: %W%    %G% - NCSA */
  452.  
  453. /* #include "help.h" */
  454.  
  455. static void
  456. reset_text ()
  457. {
  458.     window_set (textsw, TEXTSW_FIRST, 1, 0);
  459.     first = 0;
  460. }
  461. /* EOF */
  462. /* cat > src+obj/help/search_proc.c << "EOF" */
  463. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  464. /* search_proc: (static) search procedure        */
  465. /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  466. /* SCCS information: %W%    %G% - NCSA */
  467.  
  468. /* #include "help.h" */
  469.  
  470. static          Panel_setting
  471. search_proc (item, event)
  472.     Panel_item      item;
  473.     Event          *event;
  474. {
  475.     switch (event_id (event))
  476.     {
  477.         case CR:
  478.             pattern_search (item);
  479.             break;
  480.         default:
  481.             return panel_text_notify (item, event);
  482.     }
  483. }
  484. /* EOF */
  485.